package cn.harry.modular.system.controller;

import cn.harry.common.api.R;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;
import java.util.*;

@RestController
@RequestMapping("/api/dashboard")
public class DashboardController {

    @GetMapping("/stats")
    public R<Map<String, Object>> getStats() {
        Map<String, Object> data = new HashMap<>();
        data.put("userCount", 128); // TODO: 替换为userService.count()
        data.put("todayVisit", 56); // TODO: 替换为visitService.todayCount()
        data.put("systemDays", 365); // TODO: 替换为系统实际运行天数
        data.put("todoCount", 7); // TODO: 替换为todoService.count()
        return R.success(data);
    }

    @GetMapping("/visit-trend")
    public R<Map<String, Object>> getVisitTrend() {
        Map<String, Object> data = new HashMap<>();
        List<String> dates = new ArrayList<>();
        List<Integer> counts = new ArrayList<>();
        LocalDate today = LocalDate.now();
        for (int i = 6; i >= 0; i--) {
            LocalDate date = today.minusDays(i);
            dates.add(date.getMonthValue() + "-" + String.format("%02d", date.getDayOfMonth()));
            counts.add(10 + new Random().nextInt(90));
        }
        data.put("dates", dates);
        data.put("counts", counts);
        return R.success(data);
    }

    @GetMapping("/notices")
    public R<List<Map<String, String>>> getNotices() {
        List<Map<String, String>> notices = new ArrayList<>();
        notices.add(Map.of("date", "2025-07-31", "content", "系统上线"));
        notices.add(Map.of("date", "2025-07-30", "content", "新增字典自动刷新功能"));
        notices.add(Map.of("date", "2025-11-03", "content", "新增HarryData,使大屏显示更丰富！"));
        return R.success(notices);
    }
}